package com.sjzd;

import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

public class ConfigParser {
    public static String DEFAULT_PATH = "gameConfig.properties"; // 默认配置文件路径
    private static ConfigParser configParser = new ConfigParser();
    private Integer TANK_WIDTH = 0;
    private Integer TANK_HEIGHT = 0;
    private Integer TANK_SPEED = 0;
    private Integer BLOOD_WIDTH = 0;
    private Integer BLOOD_HEIGHT = 0;
    private Integer GUN_LENGTH = 0;
    private Integer WINDOW_WIDTH = 0;
    private Integer WINDOW_HEIGHT = 0;
    private Integer BULLET_WIDTH = 0;
    private Integer BULLET_HEIGHT = 0;
    private Integer BULLET_SPEED = 0;

    private ConfigParser() {
        parse(DEFAULT_PATH);
    }

    public static ConfigParser getInstance() {
        return configParser;
    }

    private  void parse(String path) {
        Properties properties = new Properties();
        InputStream configStream = ConfigParser.class.getClassLoader().getResourceAsStream(path);
        try {
            properties.load(configStream);
        } catch (IOException e) {
            System.err.println("加载属性配置文件错误！" + e.getMessage());
            System.exit(0);
        }

        try {
            TANK_WIDTH = Integer.parseInt(properties.getProperty("tankWidth"));
            TANK_HEIGHT = Integer.parseInt(properties.getProperty("tankHeight"));
            TANK_SPEED = Integer.parseInt(properties.getProperty("tankSpeed"));
            BLOOD_WIDTH = Integer.parseInt(properties.getProperty("bloodWidth"));
            BLOOD_HEIGHT = Integer.parseInt(properties.getProperty("bloodHeight"));
            GUN_LENGTH = Integer.parseInt(properties.getProperty("gunLength"));
            WINDOW_WIDTH = Integer.parseInt(properties.getProperty("windowWidth"));
            WINDOW_HEIGHT = Integer.parseInt(properties.getProperty("windowHeight"));
            BULLET_WIDTH = Integer.parseInt(properties.getProperty("bulletWidth"));
            BULLET_HEIGHT = Integer.parseInt(properties.getProperty("bulletHeight"));
            BULLET_SPEED = Integer.parseInt(properties.getProperty("bulletSpeed"));
        } catch (Exception e) {
            System.err.println("配置文件中缺少配置项，请补全" + e.getMessage());
        }

    }


    public Integer getTANK_WIDTH() {
        return TANK_WIDTH;
    }

    public Integer getTANK_HEIGHT() {
        return TANK_HEIGHT;
    }

    public Integer getTANK_SPEED() {
        return TANK_SPEED;
    }

    public Integer getBLOOD_WIDTH() {
        return BLOOD_WIDTH;
    }

    public Integer getBLOOD_HEIGHT() {
        return BLOOD_HEIGHT;
    }

    public Integer getGUN_LENGTH() {
        return GUN_LENGTH;
    }

    public Integer getWINDOW_WIDTH() {
        return WINDOW_WIDTH;
    }

    public Integer getWINDOW_HEIGHT() {
        return WINDOW_HEIGHT;
    }

    public Integer getBULLET_WIDTH() {
        return BULLET_WIDTH;
    }

    public Integer getBULLET_HEIGHT() {
        return BULLET_HEIGHT;
    }

    public Integer getBULLET_SPEED() {
        return BULLET_SPEED;
    }
}
